package com.qi.controller;

import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qi.common.RoleKey;
import com.qi.pojo.entity.Message;
import com.qi.pojo.vo.AjaxResult;
import com.qi.services.IMessageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/msg")
@Tag(name = "留言管理")
public class MessageController {

    @Resource
    private IMessageService messageService;

    @SaCheckRole(value = {RoleKey.社团管理员, RoleKey.社员}, mode = SaMode.OR)
    @Operation(summary = "发布留言")
    @PostMapping("/postMsg")
    public AjaxResult postMsg(String content) {
        messageService.postMsg(content);
        return AjaxResult.ok("留言成功");
    }

    @SaCheckRole(value = {RoleKey.社团管理员, RoleKey.社员}, mode = SaMode.OR)
    @Operation(summary = "查看留言")
    @GetMapping("/getMsgList/{current}/{size}")
    public AjaxResult getMsgList(@PathVariable("current") Long current,
                                 @PathVariable("size") Long size) {

        IPage<Message> msgList = messageService.getMsgList(current, size);
        return AjaxResult.success(msgList);
    }
}
